﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract LienHe typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class LienHeDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<LienHeDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.LienHe _currentLienHe = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxLienHeDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxLienHeErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxLienHeBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IDLienHe property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDLienHeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the HoTen property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxHoTenDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Email property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxEmailDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DiaChi property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDiaChiDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the TieuDe property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTieuDeDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the NoiDung property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNoiDungDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ThoiDiemCapNhat property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxThoiDiemCapNhatDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.LienHe> _LienHeList;
				
		/// <summary> 
		/// The list of LienHe to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.LienHe> LienHeList
		{
			get {return this._LienHeList;}
			set
			{
				this._LienHeList = value;
				this.uxLienHeBindingSource.DataSource = null;
				this.uxLienHeBindingSource.DataSource = value;
				this.uxLienHeDataGridView.DataSource = null;
				this.uxLienHeDataGridView.DataSource = this.uxLienHeBindingSource;				
				//this.uxLienHeBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxLienHeBindingSource_ListChanged);
				this.uxLienHeBindingSource.CurrentItemChanged += new System.EventHandler(OnLienHeBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnLienHeBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentLienHe = uxLienHeBindingSource.Current as Entities.LienHe;
			
			if (_currentLienHe != null)
			{
				_currentLienHe.Validate();
			}
			//_LienHe.Validate();
			OnCurrentEntityChanged();
		}

		//void uxLienHeBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.LienHe"/> instance.
		/// </summary>
		public Entities.LienHe SelectedLienHe
		{
			get {return this._currentLienHe;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxLienHeDataGridView.VirtualMode;}
			set
			{
				this.uxLienHeDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxLienHeDataGridView.AllowUserToAddRows;}
			set {this.uxLienHeDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxLienHeDataGridView.AllowUserToDeleteRows;}
			set {this.uxLienHeDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxLienHeDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxLienHeDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="LienHeDataGridViewBase"/> class.
		/// </summary>
		public LienHeDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxLienHeDataGridView = new System.Windows.Forms.DataGridView();
			this.uxLienHeBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxLienHeErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDLienHeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxHoTenDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxEmailDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDiaChiDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxTieuDeDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNoiDungDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxThoiDiemCapNhatDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxLienHeErrorProvider
			// 
			this.uxLienHeErrorProvider.ContainerControl = this;
			this.uxLienHeErrorProvider.DataSource = this.uxLienHeBindingSource;						
			// 
			// uxLienHeDataGridView
			// 
			this.uxLienHeDataGridView.AutoGenerateColumns = false;
			this.uxLienHeDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxLienHeDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDLienHeDataGridViewColumn,
		this.uxHoTenDataGridViewColumn,
		this.uxEmailDataGridViewColumn,
		this.uxDiaChiDataGridViewColumn,
		this.uxTieuDeDataGridViewColumn,
		this.uxNoiDungDataGridViewColumn,
		this.uxThoiDiemCapNhatDataGridViewColumn			});
			this.uxLienHeDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxLienHeDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxLienHeDataGridView.Name = "uxLienHeDataGridView";
			this.uxLienHeDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxLienHeDataGridView.TabIndex = 0;	
			this.uxLienHeDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxLienHeDataGridView.EnableHeadersVisualStyles = false;
			this.uxLienHeDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnLienHeDataGridViewDataError);
			this.uxLienHeDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnLienHeDataGridViewCellValueNeeded);
			this.uxLienHeDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnLienHeDataGridViewCellValuePushed);
			
			//
			// uxIDLienHeDataGridViewColumn
			//
			this.uxIDLienHeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDLienHeDataGridViewColumn.DataPropertyName = "IDLienHe";
			this.uxIDLienHeDataGridViewColumn.HeaderText = "IDLienHe";
			this.uxIDLienHeDataGridViewColumn.Name = "uxIDLienHeDataGridViewColumn";
			this.uxIDLienHeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDLienHeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDLienHeDataGridViewColumn.ReadOnly = false;		
			//
			// uxHoTenDataGridViewColumn
			//
			this.uxHoTenDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxHoTenDataGridViewColumn.DataPropertyName = "HoTen";
			this.uxHoTenDataGridViewColumn.HeaderText = "HoTen";
			this.uxHoTenDataGridViewColumn.Name = "uxHoTenDataGridViewColumn";
			this.uxHoTenDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxHoTenDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxHoTenDataGridViewColumn.ReadOnly = false;		
			//
			// uxEmailDataGridViewColumn
			//
			this.uxEmailDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxEmailDataGridViewColumn.DataPropertyName = "Email";
			this.uxEmailDataGridViewColumn.HeaderText = "Email";
			this.uxEmailDataGridViewColumn.Name = "uxEmailDataGridViewColumn";
			this.uxEmailDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxEmailDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxEmailDataGridViewColumn.ReadOnly = false;		
			//
			// uxDiaChiDataGridViewColumn
			//
			this.uxDiaChiDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDiaChiDataGridViewColumn.DataPropertyName = "DiaChi";
			this.uxDiaChiDataGridViewColumn.HeaderText = "DiaChi";
			this.uxDiaChiDataGridViewColumn.Name = "uxDiaChiDataGridViewColumn";
			this.uxDiaChiDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDiaChiDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDiaChiDataGridViewColumn.ReadOnly = false;		
			//
			// uxTieuDeDataGridViewColumn
			//
			this.uxTieuDeDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTieuDeDataGridViewColumn.DataPropertyName = "TieuDe";
			this.uxTieuDeDataGridViewColumn.HeaderText = "TieuDe";
			this.uxTieuDeDataGridViewColumn.Name = "uxTieuDeDataGridViewColumn";
			this.uxTieuDeDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTieuDeDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTieuDeDataGridViewColumn.ReadOnly = false;		
			//
			// uxNoiDungDataGridViewColumn
			//
			this.uxNoiDungDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNoiDungDataGridViewColumn.DataPropertyName = "NoiDung";
			this.uxNoiDungDataGridViewColumn.HeaderText = "NoiDung";
			this.uxNoiDungDataGridViewColumn.Name = "uxNoiDungDataGridViewColumn";
			this.uxNoiDungDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNoiDungDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNoiDungDataGridViewColumn.ReadOnly = false;		
			//
			// uxThoiDiemCapNhatDataGridViewColumn
			//
			this.uxThoiDiemCapNhatDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxThoiDiemCapNhatDataGridViewColumn.DataPropertyName = "ThoiDiemCapNhat";
			this.uxThoiDiemCapNhatDataGridViewColumn.HeaderText = "ThoiDiemCapNhat";
			this.uxThoiDiemCapNhatDataGridViewColumn.Name = "uxThoiDiemCapNhatDataGridViewColumn";
			this.uxThoiDiemCapNhatDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxThoiDiemCapNhatDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxThoiDiemCapNhatDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxLienHeDataGridView);
			this.Name = "LienHeDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxLienHeBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				LienHeDataGridViewEventArgs args = new LienHeDataGridViewEventArgs();
				args.LienHe = _currentLienHe;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class LienHeDataGridViewEventArgs : System.EventArgs
		{
			private Entities.LienHe	_LienHe;
	
			/// <summary>
			/// the  Entities.LienHe instance.
			/// </summary>
			public Entities.LienHe LienHe
			{
				get { return _LienHe; }
				set { _LienHe = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxLienHeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnLienHeDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxLienHeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnLienHeDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxLienHeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDLienHeDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].IDLienHe;
						break;
					case "uxHoTenDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].HoTen;
						break;
					case "uxEmailDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].Email;
						break;
					case "uxDiaChiDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].DiaChi;
						break;
					case "uxTieuDeDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].TieuDe;
						break;
					case "uxNoiDungDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].NoiDung;
						break;
					case "uxThoiDiemCapNhatDataGridViewColumn":
						e.Value = LienHeList[e.RowIndex].ThoiDiemCapNhat;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxLienHeDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnLienHeDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxLienHeDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDLienHeDataGridViewColumn":
						LienHeList[e.RowIndex].IDLienHe = (System.Guid)e.Value;
						break;
					case "uxHoTenDataGridViewColumn":
						LienHeList[e.RowIndex].HoTen = (System.String)e.Value;
						break;
					case "uxEmailDataGridViewColumn":
						LienHeList[e.RowIndex].Email = (System.String)e.Value;
						break;
					case "uxDiaChiDataGridViewColumn":
						LienHeList[e.RowIndex].DiaChi = (System.String)e.Value;
						break;
					case "uxTieuDeDataGridViewColumn":
						LienHeList[e.RowIndex].TieuDe = (System.String)e.Value;
						break;
					case "uxNoiDungDataGridViewColumn":
						LienHeList[e.RowIndex].NoiDung = (System.String)e.Value;
						break;
					case "uxThoiDiemCapNhatDataGridViewColumn":
						LienHeList[e.RowIndex].ThoiDiemCapNhat = (System.DateTime)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
